import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import Login from '@/components/login'
import Result from '@/components/result'
import Register from '@/components/register'
import Forget from '@/components/forget'
import Author from '@/components/author'
import Create from '@/components/create'
import Cloud from '@/components/cloud'
import Page from '@/components/page'
import Blog from '@/components/blog'
import Message from '@/components/message'
import System from '@/components/module/system'

Vue.use(Router)

//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'hash',  //去掉url中的#
  routes: [
    {
      path: '/',
      component: Home
    },
    {
      path: '/system/:id',
      name:'system',
      component: System
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/result',
      name: 'result',
      component: Result
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/forget',
      name: 'forget',
      component: Forget
    },
    {
      path: '/author/:id',
      name: 'author',
      component: Author
    },
    {
      path: '/create/:id',
      name: 'create',
      component: Create
    },
    {
      path: '/cloud/:id',
      name:'cloud',
      component: Cloud
    },
    {
      path: '*',
      name:'home',
    },
    {
      path: '/page/:name',
      name: 'page',
      component: Page
    },
    {
      path: '/blog/:id',
      name: 'blog',
      component: Blog
    },
    {
      path: '/message/:id',
      name: 'message',
      component: Message
    }
  ],
  scrollBehavior(to,from,savePosition) {
    return{
      x:0,
      y:0
    }
  }
})
